class Solution
{
public:
    int maxDivScore(vector<int> &nums, vector<int> &divisors)
    {
        int maxDivCount = -1;
        int result = 0;

        for (int divisor : divisors)
        {
            int divCount = 0;
            for (int num : nums)
            {
                if (num % divisor == 0)
                {
                    ++divCount;
                }
            }
            if (divCount > maxDivCount)
            {
                maxDivCount = divCount;
                result = divisor;
            }
            else if (divCount == maxDivCount)
            {
                result = min(result, divisor);
            }
        }

        return result;
    }
};